package eu.irreality.dai.gameplay.world;

import java.util.LinkedList;
import java.util.List;

import eu.irreality.dai.world.gen.LevelGenerator;
import eu.irreality.dai.world.gen.strategy.monster.MonsterGenerationStrategy;
import eu.irreality.dai.world.level.Level;

/**
 * A LevelDescriptor object contains information about a dungeon level: - Which
 * levels it is connected to, - How should the level be generated. A
 * LevelDescriptor acts as a placeholder for a dungeon level that hasn't been
 * generated yet. Once generated, it gets a reference to the Level itself.
 * 
 */
public class LevelDescriptor
{

    private List<LevelDescriptor> upstairsTo = new LinkedList<LevelDescriptor>();
    private List<LevelDescriptor> downstairsTo = new LinkedList<LevelDescriptor>();

    private LevelGenerator generator;
    private Level theLevel;

    private MonsterGenerationStrategy monsterGenerationStrategy;
    private int numMonsters;

    public void addUpstairsConnection(LevelDescriptor ld)
    {
	upstairsTo.add(ld);
    }

    public void addDownstairsConnection(LevelDescriptor ld)
    {
	downstairsTo.add(ld);
    }

    public List<LevelDescriptor> getUpstairsConnections()
    {
	return upstairsTo;
    }

    public List<LevelDescriptor> getDownstairsConnections()
    {
	return downstairsTo;
    }

    public void setGenerator(LevelGenerator g)
    {
	this.generator = g;
    }

    public Level getLevel()
    {
	if (theLevel == null)
	{
	    // System.out.println("generatan level");
	    theLevel = generator.generate(this);
	    // System.out.println("Generated level " + theLevel);
	    if (monsterGenerationStrategy != null)
	    {
		monsterGenerationStrategy.generateRandomMonsters(theLevel,
			numMonsters);
	    }
	}
	return theLevel;
    }

    public void setMonsterGenerationStrategy(
	    MonsterGenerationStrategy monsterGenerationStrategy)
    {
	this.monsterGenerationStrategy = monsterGenerationStrategy;
    }

    public MonsterGenerationStrategy getMonsterGenerationStrategy()
    {
	return monsterGenerationStrategy;
    }

    public int getNumMonsters()
    {
	return numMonsters;
    }

    public void setNumMonsters(int numMonsters)
    {
	this.numMonsters = numMonsters;
    }

}
